package demo4;

class Animals {
    public String name;
    public int age;

    public Animals(String name,int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println("吃东西");
    }
}
class Dog extends Animals {

    public Dog (String name,int age){
        super(name,age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 正在吃狗粮");
    }
}
public class Text {
    public static void main(String[] args) {
        Animals animals = new Dog("小黄",18);//动态绑定和向上转型
        animals.eat();
        System.out.println("===============");
        Animals animals1 = new Animals("动物",0);
        animals1.eat();
        System.out.println("===============");
        Dog dog = new Dog("小黑",2);
        dog.eat();
    }
}
